﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cspl.Calculator.Lib.Interface;
using Cspl.Calculator.Lib.Model;

namespace Cspl.Calculator.Lib
{
    public class MainCalculator
    {
        #region Private Fields

        private IBasicCalculator _calculator;
        private CalModel _data;

        #endregion

        #region Constructors

        public MainCalculator()
        {
            this._calculator = new BasicCalculator();
        }

        #endregion

        #region Properties

        public CalModel Data
        {
            get { return _data; }
            set { _data = value; }
        }

        #endregion

        #region Methods

        public int Calculate()
        {
            if (this.Data == null)
            {
                Console.WriteLine("There is no data to be calculated!");
            }
            else
            {
                switch (this.Data.Mode)
                {
                    case CalMode.Single:
                        switch (this.Data.Operation)
                        {
                            case CalOperations.Add:
                                return this._calculator.Add(this.Data.IntegerValue1, this.Data.IntegerValue2);

                            case CalOperations.Sub:
                                return this._calculator.Sub(this.Data.IntegerValue1, this.Data.IntegerValue2);

                            case CalOperations.Mul:
                                return this._calculator.Mul(this.Data.IntegerValue1, this.Data.IntegerValue2);

                            case CalOperations.Div:
                                return this._calculator.Div(this.Data.IntegerValue1, this.Data.IntegerValue2);
                        }
                        break;
                    case CalMode.List:
                        return this._calculator.ComplexListOperation(this.Data.ListOfIntegerValue, this.Data.Operation);
                }
            }
            return 0;
        }

        #endregion

    }

    public enum CalOperations { Add, Sub, Mul, Div, AddList }
    public enum CalMode { Single, List }
}
